package com.wtb.thread;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wtb.dao.OtDao;
import com.wtb.dao.impl.OtDaoImpl;
import com.wtb.domain.DataCache;
import com.wtb.domain.Other;
import com.wtb.utils.JdbcUtils;

/**
 * 
 * 每二十分钟记录一次转发数量
 * @author tacheno
 *
 */
public class CountWriteThread implements Runnable{
	private static final Log log = LogFactory.getLog(CountWriteThread.class);
	private Other other = new Other();
	OtDao otDao = new OtDaoImpl();
	public void run() {
		log.info("数量记录线程已启动");
		while (true) {
			try {
				Thread.sleep(1000*60*20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			int count = DataCache.getCount();
			other.setUni("count");
			other.setPara(String.valueOf(count));
			try {
				otDao.update(other);
				JdbcUtils.commit();
			} catch (Exception e) {
				JdbcUtils.rollback();
			}finally{
				JdbcUtils.close();
			}
		}
	}

}
